/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.edu.pucp.dp1.gui.controlador;

import Shared.ServMain;
import java.rmi.Naming;
import Shared.MatrizInterseccionSalida;

/**
 *
 * @author Edgard
 */
public class GestorConexion {

    private static GestorConexion instance;

    public static GestorConexion getInstance() {
        if (instance == null) {
            instance = new GestorConexion();
        }
        return instance;
    }

    public static Propiedades properties = Propiedades.getInstance();

    public void iniSimIntersecciones() {
        ServMain servMain;
        try {
            servMain = (ServMain) Naming.lookup(properties.getProperties().getProperty("PATH_SERVPROC"));
            servMain.iniProcesamiento();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public int getNumZonasAlto() {
        ServMain servMain;
        int aux = 0;
        try {
            servMain = (ServMain) Naming.lookup(properties.getProperties().getProperty("PATH_SERVPROC"));
            aux = servMain.getNumZonasAlto();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return aux;
    }

    public int getNumZonasLargo() {
        ServMain servMain;
        int aux = 0;
        try {
            servMain = (ServMain) Naming.lookup(properties.getProperties().getProperty("PATH_SERVPROC"));
            aux = servMain.getNumZonasLargo();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return aux;
    }

    public MatrizInterseccionSalida obtInterPorCoord(int xPos, int yPos) {
        ServMain servMain;
        MatrizInterseccionSalida aux = null;
        try {
            servMain = (ServMain) Naming.lookup(properties.getProperties().getProperty("PATH_SERVPROC"));
            aux = servMain.obtInterPorCoord(xPos, yPos);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return aux;
    }

    public boolean iniHiloGenetico() {
        boolean auxReturn=false;
        ServMain servMain;
        MatrizInterseccionSalida aux = null;
        try {
            servMain = (ServMain) Naming.lookup(properties.getProperties().getProperty("PATH_SERVPROC"));
            if(servMain.iniHiloGenetico()){
                auxReturn=true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return auxReturn;
    }

    public boolean agregarSemaforo(int xCoord, int yCoord) {
        ServMain servMain;
        boolean auxReturn = false;
        try {
            servMain = (ServMain) Naming.lookup(properties.getProperties().getProperty("PATH_SERVPROC"));
            if (servMain.agregarSemaforo(xCoord, yCoord)) {
                auxReturn = true;
            };
        } catch (Exception e) {
            e.printStackTrace();
        }
        return auxReturn;
    }

    public boolean eliminarSemaforo(int xCoord, int yCoord) {
        ServMain servMain;
        boolean auxReturn = false;
        try {
            servMain = (ServMain) Naming.lookup(properties.getProperties().getProperty("PATH_SERVPROC"));

            if (servMain.eliminarSemaforo(xCoord, yCoord)) {
                auxReturn = true;
            };
        } catch (Exception e) {
            e.printStackTrace();
        }
        return auxReturn;
    }
}
